package com.work.tqyb.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blankj.utilcode.util.ColorUtils;
import com.work.tqyb.R;
import com.work.tqyb.http.response.AirProvincesResponse;

import java.util.ArrayList;

public class AirProvincesAdapter extends BaseAdapter {

    public ArrayList<AirProvincesResponse.ProvincesInfo> cityList;
    public AirProvincesResponse.ProvincesInfo choiceInfo;

    @Override
    public int getCount() {
        return cityList == null ? 0 : cityList.size();
    }

    @Override
    public AirProvincesResponse.ProvincesInfo getItem(int position) {
        return cityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_city, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.textView = convertView.findViewById(R.id.tv_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        AirProvincesResponse.ProvincesInfo cityBean = cityList.get(position);
        viewHolder.textView.setText(cityBean.ProvinceName);
        if (choiceInfo == null) {
            viewHolder.textView.setTextColor(ColorUtils.getColor(R.color.text_color_333333));
        } else {
            if (choiceInfo.Id.equals(cityBean.Id)) {
                viewHolder.textView.setTextColor(ColorUtils.getColor(R.color.blue_4365FF));
            } else {
                viewHolder.textView.setTextColor(ColorUtils.getColor(R.color.text_color_333333));
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView textView;
    }
}
